using Digitalmes.Application.Mes.Productions.Consumptions.Commands;
using Digitalmes.Application.Mes.Productions.Consumptions.Queries;

namespace Digitalmes.WebApi.Endpoints.Mes.Productions;

/// <summary>
/// 产品用料终结点。
/// </summary>
public sealed class MaterialConsumptionEndpoint : EndpointGroupBase
{
    public override void Map(WebApplication app)
    {
        app.MapGroup(this, "mes/production", "consumption")
            .RequireAuthorization()
            .MapGet(GetMaterialConsumptionPagedListAsync, "list-page")
            .MapPut(UnboundMaterialConsumptionAsync, "unbound");
    }

    [EndpointDescription("分页获取产品用料信息")]
    public async Task<IApiResult> GetMaterialConsumptionPagedListAsync(ISender sender, [AsParameters] GetMaterialConsumptionListWithPagedQuery query)
    {
        var result = await sender.Send(query);
        return result.ToApiResult();
    }

    [EndpointDescription("解绑产品用料")]
    public async Task<IApiResult> UnboundMaterialConsumptionAsync(ISender sender, UnboundMaterialConsumptionCommand command)
    {
        var result = await sender.Send(command);
        return result.ToApiResult();
    }
}
